<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <base data-ice="baseUrl" href="../../">
  <title data-ice="title">test/test.js | API Document</title>
  <link type="text/css" rel="stylesheet" href="css/style.css">
  <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
  <script src="script/prettify/prettify.js"></script>
  
  
  <script src="script/manual.js"></script>
</head>
<body class="layout-container" data-ice="rootContainer">

<header>
  <a href="./">Home</a>
  
  <a href="identifiers.html">Reference</a>
  <a href="source.html">Source</a>
  
  <a data-ice="repoURL" href="https://git.oschina.net/kinuxroot/unique-model.js.git">Repository</a>
  <div class="search-box">
  <span>
    <img src="./image/search.png">
    <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
  </span>
    <ul class="search-result"></ul>
  </div>
</header>

<nav class="navigation" data-ice="nav"><div>
  <ul>
    
  </ul>
</div>
</nav>

<div class="content" data-ice="content"><h1 data-ice="title">test/test.js</h1>
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">&apos;use strict&apos;

let Fiber = require(&apos;fibers&apos;);

let um = require(&apos;..&apos;);
let Types = require(&apos;..&apos;).Types;

um.enablePersist();
let session = um.createSession({
    backend: &apos;mongodb&apos;,
    uri: &apos;mongodb://localhost/userman&apos;,
    options: {
        user: &apos;user&apos;,
        pass: &apos;123456&apos;
    }
});

let Image = um.model.createModel(&apos;Image&apos;, {
    path: Types.Text(),
    type: Types.Text(),
    width: Types.Integer(),
    height: Types.Integer()
});
let ImageDao = session.getDao(Image);

let User = um.model.createModel(&apos;User&apos;, {
    name: Types.Text(),
    age: Types.Integer(),
    height: Types.Double(),
    weight: Types.Double(),
    photo: Types.UObject({
        type: &apos;Image&apos;
    })
});
let UserDao = session.getDao(User);

Fiber(function() {
    main();

    process.exit();
}).run();

function main() {
    let userInfo = {
        name: &apos;kinuxroot&apos;,
        age: 20,
        height: 150.5,
        weight: 55.5,
        photo: {
            path: &apos;test.png&apos;,
            type: &apos;png&apos;,
            width: 720,
            height: 480
        }
    };

    let user = new User();
    user.id = &apos;5639f6c1a98987671bf71570&apos;;
    UserDao.refresh(user);

    console.log(user.toString());
    console.log(user.photo.toString());

    //createUser();
    //findAllUsers();
    //findUsers();
    //findOneUser();
    //getUser();
    //updateUsers();
    //updateOneUser();
    //removeUsers();
    //removeOneUser();
}

function createUser() {
    let user = new User();
    user.name = &apos;kkk&apos;;
    user.age = 28;
    user.height = 148;
    user.weight = 51.5;

    UserDao.create(user);
    console.log(user.toString());
}

function findAllUsers() {
    let users = UserDao.find({});

    console.log(users.length);
    users.forEach(user =&gt; {
        console.log(user.toString());
    });
}

function findUsers() {
    let users = UserDao.find({
        name: &apos;World&apos;
    });

    console.log(users.length);
    users.forEach(user =&gt; {
        console.log(user.toString());
    });
}

function findOneUser() {
    let user = UserDao.findOne({
        name: &apos;kkk&apos;
    });

    if ( user != null ) {
        console.log(user.toString());
    }
    else {
        console.log(null);
    }
}

function getUser() {
    let user = new User();
    user.id = &apos;56309663f77eca662076b85e&apos;;
    UserDao.refresh(user);

    console.log(user.toString());
}

function updateUsers() {
    UserDao.update({
        name: &apos;Hello&apos;
    }, {
        name: &apos;World&apos;
    }, {
        multi: true
    });
}

function updateOneUser() {
    let user = UserDao.updateOne({
        name: &apos;World&apos;
    }, {
        $set: {
            name: &apos;Hello&apos;
        }
    }, {
        new: true
    });

    console.log(user.toString());
}

function removeUsers() {
    UserDao.remove({
        name: &apos;Hello&apos;
    });
}

function removeOneUser() {
    let user = new User();
    user.id = &apos;5638298cc525db5f264b92e1&apos;;
    UserDao.remove(user);
}

</code></pre>

</div>

<footer class="footer">
  Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(0.4.3)</span></a>
</footer>

<script src="script/search_index.js"></script>
<script src="script/search.js"></script>
<script src="script/pretty-print.js"></script>
<script src="script/inherited-summary.js"></script>
<script src="script/test-summary.js"></script>
<script src="script/inner-link.js"></script>
<script src="script/patch-for-local.js"></script>
</body>
</html>
